#include <stdio.h>
#include "gameFunction.h"

int load_file(FILE* file){
    if(file==NULL){
        printf("Error! File not found!");
        return -1;
    }
    for(int i = 0; i < 20; i++){
        for(int j = 0; j < 20; j++){
            int cell;
            fscanf(file, "%d",&cell);
            if(cell != 1 && cell != 0){
                printf("Error! Abnormal data!");
                return -1;
            }
            data[i][j] = cell;
        }
        fscanf(file,"\n");
    }
    fclose(file);

    return 0;
}

int save_file(FILE* file){
    if(file == NULL){
        printf("Error! Can not find the file!");
        return -1;
    }
    for(int i = 0; i < 20; i++){
        for(int j = 0; j < 20; j++){
            fprintf(file,"%d ",data[i][j]);
        }
        fprintf(file,"\n");
    }
    fclose(file);
    return 0;
}